package org.xue.snowmall.search.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xue.snowmall.common.utils.PageUtils;
import org.xue.snowmall.search.entity.GoodsEntity;
import org.xue.snowmall.search.feign.OrderFeignService;
import org.xue.snowmall.search.service.GoodsService;
import org.xue.snowmall.search.vo.SearchVo;
import org.xue.snowmall.common.utils.R;

import java.io.IOException;
import java.util.Map;

/**
 * @author 小刘的小张
 * @version 1.0
 * @description: TODO
 * @date 2021/9/22 18:32
 */
@Controller
public class WebSearchController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OrderFeignService orderFeignService;
    @RequestMapping({"/","/search.html"})
    public String search(SearchVo vo
    , Model model
    , @RequestParam(value = "page",defaultValue = "1") Integer page
    ,@RequestParam(value = "limit",defaultValue = "2") Integer limit) throws IOException {

        PageUtils<GoodsEntity> list = goodsService.esList(vo,page,limit);
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping("/saveOrder")
    @ResponseBody
    public R saveOrder(@RequestParam Map<String, Object> params) {


        return orderFeignService.order(params);
    }

}
